﻿using System;

namespace _030_索引器
{
    class Sentence
    {
        string[] words = "The quick bown fox".Split();

        public string this[int wordNum] // 索引器
        {
            get { return words[wordNum]; }
            set { words[wordNum] = value; }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            // 索引器为访问类或结构体中封装的列表或字典型数据元素提供了自然的访问接口。
            string s = "hello";
            Console.WriteLine(s[0]); // 'h'
            Console.WriteLine(s[3]); // 'l'


            Sentence st = new Sentence();
            Console.WriteLine(st[3]); // fox
            st[3] = "kangaroo";
            Console.WriteLine(st[3]); // kangaroo

            Console.ReadKey();
        }
    }
}